import 'package:get/get.dart';
import 'package:hc_bot_kit/hc_bot_kit.dart';
import 'package:hc_bot_pro/common/speech/service.dart';
import 'package:hc_bot_pro/guide/index.dart';

import '../../routes.dart';

class Purpose {
  late String action;
  late dynamic params;

  Purpose.fromJson(Map<String, dynamic> json) {
    action = json['action'];
    params = json['params'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['action'] = this.action;
    data['params'] = this.params;
    return data;
  }
}

extension PurposeExtension on Purpose {
  Future handle() async {
    switch (action.toLowerCase()) {
      case "play":
        {
          await Get.toNamed(Routes.kPlayer, arguments: params);
        }
      case "list":
        {
          return Get.toNamed(Routes.kCureMenu);
        }
      case "go":
        {
          final dst = params["content"];
          await Get.dialog(
            GuidePage(),
            arguments: dst,
            barrierDismissible: false,
          );
          await Future.delayed(2.seconds);
          await Get.find<HCAISpeechService>().asr.sleep();
        }
      default:
        break;
    }
  }
}
